import { axios } from '@/service/service'
import { CreateRuleGroupReq, CreateRuleReq, PartitionDef } from './types'

export function createRuleGroupData(data: CreateRuleGroupReq): any {
  return axios({
    url: '/monitor/rules/createCollection',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function getRuleGroup(
  tableName: string | number,
  schemaName: string | number
): any {
  return axios({
    url: `/monitor/rules/queryAllRulesCollection/${schemaName}/${tableName}`,
    method: 'get'
  })
}

export function getRuleListData(id: number | string): any {
  return axios({
    url: `/monitor/rules/queryAllRules/${id}`,
    method: 'get'
  })
}

export function getTriggerListData(page: number, pageSize: number): any {
  return axios({
    url: `/monitor/trigger/getTriggerLogVO/${page}/${pageSize}`,
    method: 'get'
  })
}

export function deleteRuleGroupData(id: number): any {
  return axios({
    url: `/monitor/rules/deleteOneCollection/${id}`,
    method: 'delete'
  })
}

export function getAlarmRecordListData(page: number, pageSize: number): any {
  return axios({
    url: `/monitor/alert/getAlertMsgVO/${page}/${pageSize}`,
    method: 'get'
  })
}

export function createRuleData(data: CreateRuleReq): any {
  return axios({
    url: '/monitor/rules/saveOrUpdateOneRule',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function manualTrigger(id: number): any {
  return axios({
    url: `/monitor/trigger/triggerExecute/admin/${id}`,
    method: 'get'
  })
}

export function getHiveMetaStoreData(
  tableName: string | number,
  schemaName: string | number
): any {
  return axios({
    url: `/monitor/hiveMetaStore/${schemaName}/${tableName}/detail`,
    method: 'get'
  })
}

export function debugPartitionDefDsl(params: PartitionDef): any {
  return axios({
    url: '/monitor/execute/debugDsl',
    method: 'get',
    params: {
      ...params
    }
  })
}

export function readAlarmRecordById(id: number): any {
  return axios({
    url: `/monitor/alert/updateSend/${id}`,
    method: 'put',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    transformRequest: (params) => JSON.stringify(params)
  })
}
